package api

import (
	"gitee.com/Hu-Lyndon/distill-resk/infra"
	log "github.com/sirupsen/logrus"
)

var apiInitializerRegister *InitializeRegister = new(InitializeRegister)

//注册WEB API初始化对象
func RegisterApi(ai Initializer) {
	apiInitializerRegister.Register(ai)
}

func SetupApi(ai Initializer)  {
	apiInitializerRegister.Setup(ai)
}

// 获取注册的web api初始化对象
func GetApiInitializers() []Initializer {
	return apiInitializerRegister.Initializers
}

func GetSetupApis() []Initializer {
	return apiInitializerRegister.SetupApis
}

type WebApiStarter struct {
	infra.BaseStarter
}

func (w *WebApiStarter) Setup(ctx infra.StarterContext) {
	for _, v := range GetApiInitializers() {
		log.Debugf("Init Api:%v", v)
		v.Init()
	}
	for _, v:= range GetSetupApis() {
		log.Debugf("Setup Api:%v", v)
		v.Setup()
	}
}
